#include "calculator.h"
#include "./ui_calculator.h"


static double num = 0.0;
enum STATUS {
    NUMBER,
    OPERATOR,
    ERROR
};

Calculator::Calculator(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Calculator)
{
    ui->setupUi(this);

    const QString STR[ROW][COLUMN] = {
        {"AC", "+/-", "%", "/"},
        {"7",  "8",   "9", "*"},
        {"4",  "5",   "6", "-"},
        {"1",  "2",   "3", "+"},
        {"00", "0",   ".", "="}
    };

    mainLayout = new QGridLayout(this);
    mainLayout->setSpacing(3);
    mainLayout->setContentsMargins(5, 5, 5, 5);

    lineEdit = new QLineEdit("0", this); // 文本显示区域
    lineEdit->setAlignment(Qt::AlignRight);
    lineEdit->setReadOnly(true);
    lineEdit->setStyleSheet("font-size: 24px;");

    mainLayout->addWidget(lineEdit, 0, 0, 1, COLUMN);

    for (int i = 0; i < ROW; i++) {
        btnList.push_back(QVector<QPushButton *>());
        for (int j = 0; j < COLUMN; j++) {
            QPushButton* btn = new QPushButton(STR[i][j], this);
            btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
            btnList[i].push_back(btn);
            mainLayout->addWidget(btn, i + 1, j, 1, 1);
        }
    }
}

Calculator::~Calculator()
{
    delete ui;
}
